package cn.edu.nuc.creditSystem.controller.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;

import cn.edu.nuc.creditSystem.bean.user.Role;
import cn.edu.nuc.creditSystem.controller.BaseController;
import cn.edu.nuc.creditSystem.service.BaseService;
import cn.edu.nuc.creditSystem.service.user.service.RoleService;

@Controller
@RequestMapping("/cs/user/role")
public class RoleController extends BaseController<Role>{
	@Autowired
	private RoleService rs;
	@Override
	protected BaseService<Role> getService() {
		return rs;
	}

	@Override
	protected String getPrefix() {
		return "/role/";
	}
	@ResponseBody
	@RequestMapping(value="/saveRole")
	private String saveRole(Role role){
		Gson g=new Gson();
		if(role.getId()!=null){//执行更新操作
			return g.toJson(rs.updateRole(role));
		}else{
			return g.toJson(rs.insert(role));
		}
	}
	@ResponseBody
	@RequestMapping("/edit{id}")
	private Role eidt(@PathVariable("id") int id){
		return rs.get(id);
	}
	@ResponseBody
	@RequestMapping("/combobox")
	private List<Role> combobox(){
		return rs.getAll(null);
	}
}
